#pragma once
#include <Windows.h>
#include <string>
#include <vector>
#include "CyDelegate.h"

class CyGUIEditBox
{
private:
	INT _id;
	HWND _hwnd;
	CyDelegate_base * _enterHandler;
	WNDPROC _oldProc;

public:
	// parentHWND: the handle of the parent that contains the button
	// id: the id of the edit box
	CyGUIEditBox(HWND parentHWND, INT id);
	~CyGUIEditBox(void);

	// Set name for the edit box
	void SetText(const std::wstring& str);

	// Get name of the edit box
	// str: the string used to contain the name
	// return: the string above, for convenience
	std::wstring& GetText(std::wstring& str) const;

	// Get integer value of the edit box
	int GetInt() const;

	// Get float value of the edit box
	float GetFloat() const;

	// Get double value of the edit box
	double GetDouble() const;
	
	// set handler for click event
	template <class R> void SetHandler(R * obj,
		typename CyDelegate<R>::Handler handler)
	{
		if (obj == NULL || handler == NULL)
		{
			if(_enterHandler != NULL)
				delete _enterHandler;
			_enterHandler = NULL;
		}
		else
		{
			_enterHandler = new typename CyDelegate<R>(obj, handler);
		}
	}

private:
	BOOL HandleMessage(HWND hWnd,
		UINT message, WPARAM wParam, LPARAM lParam);

// Static member
	static void AddFilter(CyGUIEditBox *filter);

	static void RemoveFilter(CyGUIEditBox *filter);

	typedef std::vector<CyGUIEditBox*> FilterList;

	// List of message filters
	static FilterList _filterList;

	friend LRESULT CALLBACK _editBoxProc(HWND hwnd,
		UINT message, WPARAM wParam, LPARAM lParam);
};

